#include "XmlGenerator.h"
typedef cblp::XmlGenerator XML;

#include "RoRouter.h"
#include "RoServerModule.h"


RoRouter::RoRouter(RoServerModule * parent)
{
    setName("ROUTER");

    methods["query-components"]["description"] = "Returns the list of connected components.";

    // QChildEvent(ChildAdded) must be sent after this object being fully constructed
    setParent(parent);
}


RoRouter::~RoRouter()
{
}


RoServerModule * RoRouter::parentModule() const
{
    return qobject_cast<RoServerModule*>(parent());
}


RoAbstractComponent::RoMethodResult RoRouter::ro_query_components(RoIqStanza, QDomDocument * answer)
{
    XML answerGen("components");
    {
        QList<QString> componentNames = parentModule()->clients.components();
        componentNames += "ROUTER";
        foreach ( QString name, componentNames )
            answerGen.appendChild( XML("component")("name", name) );
    }

    *answer = answerGen.toDocument();
    return FinishedSuccessfully;
}
